package com.hwtx.form.domain.def;

import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.Data;
import lombok.EqualsAndHashCode;

import java.util.List;
import java.util.Map;
import java.util.Objects;

@Data
@JsonInclude(JsonInclude.Include.NON_NULL)
public class Select {
    private List<Option> options;

    @Data
    @JsonInclude(JsonInclude.Include.NON_NULL)
    public static class GroupSelect {
        private List<GroupOption> options;
        private String apply;
    }

    @Data
    @JsonInclude(JsonInclude.Include.NON_NULL)
    public static class NestedSelect {
        private List<NestedOption> options;
    }

    @Data
    @JsonInclude(JsonInclude.Include.NON_NULL)
    public static class CommonSelect {
        private List<Map<String, Object>> options;
    }

    @Data
    @JsonInclude(JsonInclude.Include.NON_NULL)
    public static class Option {
        private String label;
        private String value;
        private String comment;
        private Boolean disabled;

        public Option() {
        }

        public Option(String label, String value) {
            this.label = label;
            this.value = value;
        }

        @Override
        public boolean equals(Object o) {
            if (this == o) return true;
            if (o == null || getClass() != o.getClass()) return false;
            Option option = (Option) o;
            return Objects.equals(label, option.label) && Objects.equals(value, option.value);
        }

        @Override
        public int hashCode() {
            return Objects.hash(label, value);
        }
    }

    @Data
    public static class GroupOption {
        private String label;
        private List<Option> children;
    }

    @EqualsAndHashCode(callSuper = true)
    @Data
    public static class NestedOption extends Option {
        private List<NestedOption> children;
    }
}

